<template>
  <div class="hb-cpt__scroll-list message-home__list">
    <div
      v-for="(item, index) in commentList"
      :key="index"
      class="message__follow-item"
    >
      <div class="follow-item__avatar-wrapper">
        <img :src="item.avatar" alt="" class="follow-item__avatar" />
      </div>
      <div class="follow-item__content">
        <div class="comment-wrapper">
          <!-- 左侧文字区 -->
          <div class="comment-left">
            <div class="comment-line">
              <span class="follow-item__username">{{ item.senderName }}</span>
              评论了你的<span v-if="item.targetType === 1">动态</span>
              <span v-else-if="item.targetType === 2">文章</span>
              <span v-else>评论</span>
            </div>
            <div class="comment-text">“{{ item.commentContent }}”</div>
          </div>
          <!-- 右侧展示被评论对象内容 -->
          <div class="comment-preview-inline">{{ item.targetContent }}</div>
        </div>
      </div>
    </div>
    <div class="scroll-list__no-more-desc">暂无更多内容</div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { getCommentNotice } from '@/apis/notice'
import { useAccountStore } from '@/stores/useAccountStore'

const accountStore = useAccountStore()
const uid = accountStore.uid

const commentList = ref([])

onMounted(async () => {
  try {
    const res = await getCommentNotice(uid)
    if (res?.code === '200' && Array.isArray(res.data)) {
      commentList.value = res.data
    }
  } catch (err) {
    console.error('获取评论通知失败', err)
  }
})
</script>

<style scoped>
.hb-cpt__scroll-list {
  padding: 12px 16px;
}
.message__follow-item {
  display: flex;
  align-items: flex-start;
  padding: 10px 0;
  border-bottom: 1px solid #eee;
}
.follow-item__avatar-wrapper {
  margin-right: 12px;
}
.follow-item__avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
}
.follow-item__content {
  flex: 1;
}

/* 整体排布左右结构 */
.comment-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  gap: 12px;
}

/* 左侧主文字区域 */
.comment-left {
  flex: 1;
  min-width: 0;
}

.comment-line {
  font-size: 13px;
  color: #888;
  margin-bottom: 4px;
  word-break: break-word;
}

.follow-item__username {
  font-weight: 500;
  font-size: 14px;
  color: #333;
  margin-right: 4px;
}

.comment-text {
  font-size: 13px;
  color: #666;
  word-break: break-word;
}

/* 右侧 targetContent 展示区 */
.comment-preview-inline {
  width: 70px;
  font-size: 13px;
  color: #444;
  background-color: #f5f5f5;
  padding: 4px 8px;
  border-radius: 4px;

  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-word;

  align-self: stretch;
  box-sizing: border-box;
}

.scroll-list__no-more-desc {
  text-align: center;
  color: #999;
  font-size: 13px;
  padding: 12px 0;
}
</style>
